package com.hq.fxh.No2_BBS.Adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hq.fxh.Modle.PlateSoreModle;
import com.hq.fxh.R;
import com.hq.fxh.Utils.ClickUtils;
import com.hq.fxh.Utils.Tool;

import java.util.List;

/**
 * /**
 *
 * @author 薛
 * @ClassName
 * @Description :
 * @Created 2017/8/18
 * @Email xlwenhao1858@sina.com
 */


public class Ladapter_PlateName extends BaseAdapter {
    List<PlateSoreModle.DataBean.ItemsBean> data;
    PlateNameCallBack plateNameCallBack;

    public Ladapter_PlateName(List<PlateSoreModle.DataBean.ItemsBean> data, PlateNameCallBack plateNameCallBack) {
        this.data = data;
        this.plateNameCallBack = plateNameCallBack;
    }

    @Override
    public int getCount() {
        return data == null ? 0 : data.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(final int i, View convertView, ViewGroup parent) {
        View view = convertView;
        ViewHolder viewHolder = null;
        if (view == null || !(view.getTag() instanceof ViewHolder)) {
            view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_plate_name, null);
            viewHolder = new ViewHolder(view);
            view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }
        Tool.setStringToText( viewHolder.tvPlateName,data.get(i).getCategory());
        Tool.setIntToText( viewHolder.tvPlateNum,data.get(i).getItem_count(),"Ladapter_PlateName-->tvPlateNum");
        Tool.setUrlToImage( parent.getContext(),data.get(i).getIcon(),viewHolder.imagePlateIcon);

        viewHolder.tvPlateFocus.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                plateNameCallBack.onCallFocus(view, i, null);
            }
        });
        final String s = viewHolder.tvPlateName.getText().toString();
        viewHolder.layoutPlateNameItem.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                plateNameCallBack.onCallName(view, i, data.get(i));
            }
        });
        return view;
    }


    static class ViewHolder {
        protected ImageView imagePlateIcon;
        protected TextView tvPlateName;
        protected TextView tvPlateNum;
        protected LinearLayout layoutPlateNameItem;
        protected TextView tvPlateFocus;

        ViewHolder(View rootView) {
            initView(rootView);
        }

        private void initView(View rootView) {
            imagePlateIcon = (ImageView) rootView.findViewById(R.id.image_Plate_icon);
            tvPlateName = (TextView) rootView.findViewById(R.id.tv_Plate_name);
            tvPlateNum = (TextView) rootView.findViewById(R.id.tv_Plate_num);
            layoutPlateNameItem = (LinearLayout) rootView.findViewById(R.id.layout_PlateNameItem);
            tvPlateFocus = (TextView) rootView.findViewById(R.id.tv_Plate_Focus);
        }
    }

    public interface PlateNameCallBack {
        void onCallFocus(View view, int position, Object data);

        void onCallName(View view, int position, Object data);

    }
}
